//归类操作对象
var sameType = {"Range":false,"Measure":false,"Point1":false,"Point2":false,"LineString1":false,"LineString2":false,"Polygon1":false,"dragMap":false,"zoomInOut":false,"search":false};
//标识放大和平移事件
var resolutionPan = false;
//记录前一屏，后一屏
var beforeStep=[],afterStep=[];
var userHandle = false;
var index = 1;
// feature
var sketch;
var helpTooltipElement;
var helpTooltip;
var measureTooltipElement;
var measureTooltip;
var tempTooltipElement;
var tempTooltip;
var tagTooltipElement;
var tagTooltip;
var operateTooltipElement;
var operateTooltip;
//测面积时的提示
var continuePolygonMsg = '单击确定起点，双击结束';
//测路径时的提示
var continueLineMsg = '单击确定起点，双击结束';
var draw;
//储存vector图层的所有几何图形数据
var collection = new Array();
//存储单个几何图形的数据
var geomFeature;
//操作的画笔类型,存储在feature中，用于区分类型
var type;
//用于存放feature集合
var allFeatures = new ol.Collection();
//zoom
var maxZoom = 18,
	minZoom = 3,
	initZoom = 15;
//街市省
var level = {
	"street": 17,
	"city": 10,
	"province": 5
};
//定时器
var slider, holde;

//地图图层
var mapLayer = new ol.layer.Tile({
	source: new ol.source.XYZ({
		projection: "EPSG:4326",
		url: "http://t4.tianditu.com/DataServer?T=vec_c&x={x}&y={y}&l={z}"
	})
});
//文字图层
var wordLayer = new ol.layer.Tile({
	source: new ol.source.XYZ({
		projection: "EPSG:4326",
		url: "http://t7.tianditu.com/DataServer?T=cva_c&x={x}&y={y}&l={z}"
	})
});
//地图
var normalLayer = new ol.layer.Tile({
	source: new ol.source.TileArcGISRest({
		url: "http://10.120.20.122:6080/arcgis/rest/services/topology/tianjin1/MapServer"
	})
});
//建筑
var buildingLayer = new ol.layer.Tile({
	source: new ol.source.TileArcGISRest({
		url: "http://10.120.20.122:6080/arcgis/rest/services/1/MyMapService/MapServer"
	})
});
//遥感
var senseLayer = new ol.layer.Tile({
	source: new ol.source.TileArcGISRest({
		url: "http://10.120.20.122:6080/arcgis/rest/services/topology/遥感/MapServer"
	})
});
senseLayer.setVisible(false);
//道路图层
var roadLayer = new ol.layer.Tile({
	source: new ol.source.TileArcGISRest({
		url: "http://10.120.20.122:6080/arcgis/rest/services/topology/网络分析/MapServer"
	})
});
//绘图 数据源
var source = new ol.source.Vector({
	features: allFeatures
});
//测距侧面积数据源
var sourceLayer = new ol.source.Vector();

//根据所设置的type值获取样式
var styleFunction = function(feature, resolution) {
	if (feature.get("type")) {
		return styles[feature.get("type")];
	}
	return styles["GeometryCollection"];
};
//用户自定义绘制图层
var vector = new ol.layer.Vector({
	source: source,
	//回调函数，当drawend结束时调用
	style: styleFunction
});
//用户自定义绘制图层(测距/测面积的存放)
var vectorLayer = new ol.layer.Vector({
	source: sourceLayer,
	//回调函数，当drawend结束时调用
	style: styleFunction
});
var view = new ol.View({
	center: [117.39758, 39.14407], //必需
	projection: "EPSG:4326", //必需
	extent: [117.32179299038442, 39.1131412, 117.46141976220655, 39.18537655771531],
	zoom: initZoom,
	minZoom: minZoom,
	maxZoom: maxZoom
});
/**
 * 初始化map
 */
var map = new ol.Map({
	layers: [mapLayer, wordLayer, roadLayer, vector, vectorLayer] /*[normalLayer,senseLayer,buildingLayer,roadLayer,vector, vectorLayer]*/ ,
	target: 'map',
	view: view,
	controls: [
		new ol.control.FullScreen(), new ol.control.ScaleLine(), new ol.control.ZoomSlider(),new ol.control.OverviewMap()/*, new ol.control.MousePosition()*/
	],
	interactions: ol.interaction.defaults({shiftDragZoom:false})
});
